package main
import (
	"fmt"
	"golang.org/x/net/context"
	"google.golang.org/grpc"
	"net"
	"testrpc/kibana"
)

//定义服务
type Kibana struct{}

//服务中的方法必须要全都实现
func (k *Kibana) Write(ctx context.Context, req *kibana.WriteRequest) (rsp *kibana.WriteResponse, err error) {
	rsp.Code = 0
	rsp.Message = "success"
	rsp.Data = map[string]string{"tag":req.Tag,"info":req.Info,"level":req.Level}
	//err = logics.WriteLog(req.Tag, req.Info, req.Level)
	return rsp, err
}

func main() {
	//将服务注册到consul
	serviceAddress := ":50061"
	kibanaServer := new(Kibana)
	//创建tcp监听
	ls, _ := net.Listen("tcp", serviceAddress)
	//创建grpc服务
	gs := grpc.NewServer()
	//kibanaServer
	kibana.RegisterKibanaServer(gs, kibanaServer)
	//启动服务
	gs.Serve(ls)
}
